
//Axios封装
// import axios from 'axios'
// import qs from 'qs'
const axios = require('axios')
const qs = require('qs')

//清除请求空参数
let Eliminate = (data) => {

    for (let key in data) {
  
      if(data[key] == ''){
        delete data[key]
      }
       
    }
    return data
  }

axios.interceptors.request.use(config => {

    return config
}, error => {
    return Promise.reject(error)
})

axios.interceptors.response.use(response => response, error => Promise.resolve(error.response))

function checkStatus(response) {
    
    if (response.status == 200 || response.status == 304) {

        return response
    }else{
        
        
    }

    return {
        
        data: {
            code: -404,
            message: response.statusText,
            data: response.statusText,
        }
    }
}

function checkCode(res) {

    if(res.data){

    }
   

    return res
}

const axiosPackage = {
    
    post(url, data) {

        return axios({
            method: 'post',
            url,
            data: qs.stringify(data),
            timeout: 30000,
            headers: {
                'X-Requested-With': 'XMLHttpRequest',
                'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
            }
        }).then(checkStatus).then(checkCode)
    },

    get(url, params) {

        return axios({
            method: 'get',
            url,
            params,
            timeout: 30000,
            headers: {
                'X-Requested-With': 'XMLHttpRequest'
            }
        }).then(checkStatus).then(checkCode)
    }
}